<template>
	<view class="app-container">
		<view class="list" v-if="indexList.length > 0">
			<u-list>
				<u-list-item v-for="item in indexList" :key="item.id">
					<view class="msg">
						<view class="title">
							<u-badge class="badge" :isDot="true" type="error"></u-badge>
							<text>通知</text>
							<text class="time">{{item.update_time}}</text>
						</view>
						<u-cell :border="false" :title="item.xexplain" :value="item.earnings">
						</u-cell>
					</view>
				</u-list-item>
			</u-list>
		</view>
	</view>
</template>

<script>
	import {
		messageList,
		messageStatus
	} from "@/api/mall.js"
	export default {
		data() {
			return {
				indexList: [],
				params: {
					current: 2,
					size: 10,
				}
			}
		},
		onLoad() {
			this.getList();
		},
		onUnload() {
			this.updataStatus()
		},
		methods: {
			getList() {
				uni.showLoading()
				messageList(this.params).then(res => {
					console.log(res);
					if (res.total > 0) {
						this.indexList = res.records
					} else {
						this.indexList = []
					}
				})
				uni.hideLoading()
			},
			updataStatus() {
				messageStatus().then(res => {
					uni.setStorageSync("message", 0)
				})
			},
		}
	}
</script>

<style>
	page {
		background-color: #f8f8f8;
	}

	.app-container {
		padding: 0 20px;
	}

	.msg {
		background: #fff;
		margin-bottom: 20px;
		border-radius: 8px;
	}

	.title {
		padding: 10px 15px;
		border-bottom: 1rpx solid rgb(214, 215, 217);
		display: flex;
		align-items: center;
	}

	.badge {
		margin-right: 5px;
	}

	.time {
		margin-left: auto;
		font-size: 13px;
		color: #8F9BB3;
	}
</style>
